package edu.buaa.act.travel.m.page;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import edu.buaa.act.travel.m.Constants;
import edu.buaa.act.travel.m.R;
import edu.buaa.act.travel.m.adapter.TripAdapter;
import edu.buaa.act.travel.m.model.TripModel;
import edu.buaa.act.travel.m.data.TripSimp;

public class TripListActivity extends BaseActivity {
	
	private ListView mListTrip;
	private TripAdapter mTripAdapter;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.trip_list_activity);
        
        setupLeftPanelButton();
        setRightPanelButtonVisibility(View.GONE);
        
        final String result = getIntent().getStringExtra(Constants.EXTRA_RESULT);
        mListTrip = (ListView) findViewById(R.id.list_trip);
        mTripAdapter = new TripAdapter(this, new TripModel(result).getTrips());
        mListTrip.setAdapter(mTripAdapter);
        
        mListTrip.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int position,
					long arg3) {
				forward(position);
			}
		});
    }
    
    private void forward(final int position) {
    	final TripSimp trip = (TripSimp) ((TripAdapter)mListTrip.getAdapter()).getItem(position);
    	final Intent intent = new Intent(this, TripDetailActivity.class);
    	intent.putExtra(Constants.EXTRA_TRIP, trip);
    	startActivity(intent);
    }
}
